package com.yidu.hbatsams.action.AtsSchemeAduit;

import com.yidu.hbatsams.domain.AtsEmpExpert;
import com.yidu.hbatsams.domain.AtsSchemeAudit;
import com.yidu.hbatsams.domain.AtsSchemeExpert;
import com.yidu.hbatsams.service.AtsSchemeAuditServicefx;
import com.yidu.hbatsams.utils.Message;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("atsAduit")
public class AtsSchemeAduitActionfx {
    @Resource
    private AtsSchemeAuditServicefx atsSchemeAuditServicefx;

    @RequestMapping("/findAll")
    @ResponseBody
    public Map<String,Object> findAll(@RequestParam("page") Integer pageNum, @RequestParam("limit")Integer pageSize,String schemeType){
        Map<String,Object> map = new HashMap<>();
        int count = atsSchemeAuditServicefx.count(schemeType);
        List<AtsSchemeAudit> list = atsSchemeAuditServicefx.selectByPrimaryKey(pageSize,pageNum,schemeType);
        map.put("msg","");
        map.put("code",0);
        map.put("data",list);
        map.put("count",count);
        return map;
    }

    /**
     * 查询下拉:专家
     * @param expertName
     * @return
     */
    @RequestMapping("/selectAll")
    @ResponseBody
    public List<AtsEmpExpert> selectAll(String expertName){
        List<AtsEmpExpert> list = atsSchemeAuditServicefx.selectAll(expertName);
        return list;
    }

    /**
     * 审核通过修改数据
     * @param record
     * @param expert
     * @return
     */
    @RequestMapping("/update")
    @ResponseBody
    public Message updateByPrimaryKeySelective(AtsSchemeAudit record, AtsSchemeExpert expert,String saId){
        int row = 0;
        Message message = new Message();


        if(record.getSaId()!=null){
            row = atsSchemeAuditServicefx.updateByPrimaryKeySelective(record, expert,saId);
        }

        if(row>0){
            message.setMsg("yes");
            message.setNum(1);
        }else{
            message.setMsg("no");
            message.setNum(0);
        }
        return message;
    }
    @RequestMapping("/updateno")
    @ResponseBody
    public Message updateByPrimaryKey(AtsSchemeAudit record){
        int row = 0;
        Message message = new Message();
        System.out.println();

        if(record.getSaId()!=null){
            row = atsSchemeAuditServicefx.updateByPrimaryKey(record);
        }

        if(row>0){
            message.setMsg("yes");
            message.setNum(1);
        }else{
            message.setMsg("no");
            message.setNum(0);
        }
        return message;
    }
}
